package com.base.study.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;

import com.base.commonlib.base.CBaseMvpFragment;
import com.base.commonlib.utils.RxBus2;
import com.base.study.R;
import com.base.study.adapter.CurriculumCatalogAdapter;
import com.base.study.bean.CurriculumCatalogBean;
import com.base.study.databinding.FragmentCurriculumCatalogBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zw on 2020/2/14.
 * 目录
 */

public class CurriculumCatalogFragment extends CBaseMvpFragment{

    protected FragmentCurriculumCatalogBinding mBinding;
    private CurriculumCatalogAdapter curriculumCatalogAdapter;
    private List<CurriculumCatalogBean> curriculumCatalogBeans;

    @Override
    public void init() {
        mBinding = (FragmentCurriculumCatalogBinding) mRootBinding;
    }

    @Override
    public void start() {
        initData();
    }


    private void initData(){
        Bundle bundle =this.getArguments();

        curriculumCatalogBeans=new ArrayList<>();
        curriculumCatalogBeans= (List<CurriculumCatalogBean>) bundle.getSerializable("curriculumCatalogBeans");

        if (curriculumCatalogBeans !=null && curriculumCatalogBeans.size()>0){
            mBinding.empty.setVisibility(View.GONE);
            curriculumCatalogAdapter =new CurriculumCatalogAdapter(mContext,curriculumCatalogBeans);
            mBinding.rv.setAdapter(curriculumCatalogAdapter);
            mBinding.rv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                    CurriculumCatalogBean.WaresBean bean = curriculumCatalogBeans.get(groupPosition).getWares().get(childPosition);
                    if (bean!=null) {
                        RxBus2.getInstance().post(bean);
                    }
                    return false;
                }
            });
        }


        //mPresenter.getData(id);
    }


    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_curriculum_catalog;
    }



}
